function [chroms,Z]=global_search(total_op_num,sizepop,chroms,FF,Z)
global operation_machine operation_time num_machine num_job num_op
%% 全局式
a=1;
for j=1:num_job
    b=num_op(j);
    temp(1,a:(a+b-1))=j;
    a=a+b;
end 


for p=size(chroms,1)+1:sizepop
    machine_time=zeros(1,num_machine);%全局搜索
    machine_choose=zeros(2,num_job,num_machine);
    job=randperm(num_job,num_job);%打乱工件顺序
    for i=1:num_job%遍历工件
        op_machine=operation_machine{1,job(i)};%工件job(i)的工序及其机器集
        for j=1:num_op(job(i))%遍历工序
            cm=op_machine{j};%能选的机器
            tm=operation_time{job(i)}{j};%对应时间
            machine_temp=machine_time;
            machine_temp(cm)=machine_temp(cm)+tm;
            [mini,ind]=min(machine_temp(cm));
            machine_time(cm(ind))=mini;
            machine_choose(1,job(i),j)=cm(ind);
            machine_choose(2,job(i),j)=tm(ind);
        end
    end
    
    chrom=zeros(3,total_op_num*3);
    for i=1:3   
        rtemp=randperm(total_op_num);%随机生产工序码
        aa=temp(rtemp);
        chrom(i,1:total_op_num)=aa;
        for j=1:total_op_num
            chrom(i,total_op_num+j)=machine_choose(1,aa(j),length(find(aa(1:j)==aa(j))));
            chrom(i,total_op_num*2+j)=machine_choose(2,aa(j),length(find(aa(1:j)==aa(j))));
        end
    end
    [zz,~,~,~]=fitness(chrom,FF);
    [ZZ,zind]=min(zz);
    chroms(p,:)=chrom(zind,:); 
    Z(p)=ZZ;
end
end
